#include <stdio.h>

const int N = 30;

long long f[N][N];
int root[N][N];
int score[N];
int n;

void print(int l, int r){
    if(l > r) return;
    printf("%d ", root[l][r]);
    if(l == r) return;
    print(l, root[l][r] - 1);
    print(root[l][r] + 1, r);
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d", &score[i]);

    for(int i = 1; i <= n; i++) {
        f[i][i] = score[i];
        root[i][i] = i;
    }

    for(int l = 1; l <= n; l++){
        for(int i = 1; i + l <= n; i++){
            int j = i + l;
            for(int k = i; k <= j; k++){
                long long tmp = (k == i? 1: f[i][k-1]) * (k == j? 1: f[k+1][j]) + score[k];
                if(tmp > f[i][j]){
                    f[i][j] = tmp;
                    root[i][j] = k;
                }
            }
        }
    }
    printf("%lld\n", f[1][n]);
    print(1, n);
    printf("\n");

    return 0;
}
